<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Pages - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.navigation.pages.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.navigation.pages.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.navigation.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.navigation.html">Zend_Navigation</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.navigation.containers.html">Containers</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.navigation.pages" class="section"><div class="info"><h1 class="title">Pages</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Navigation</span> ships with two page types:

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <a href="zend.navigation.pages.html#zend.navigation.pages.mvc" class="link">MVC pages</a>
                     – using the class <span class="classname">Zend_Navigation_Page_Mvc</span>
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <a href="zend.navigation.pages.html#zend.navigation.pages.uri" class="link">URI pages</a>
                     – using the class <span class="classname">Zend_Navigation_Page_Uri</span>
                </p>
            </li>
        </ul>

        MVC pages are link to on-site web pages, and are defined using MVC
        parameters (<code class="code">action</code>, <code class="code">controller</code>,
        <code class="code">module</code>, <code class="code">route</code>, <code class="code">params</code>). URI
        pages are defined by a single property <code class="code">uri</code>, which give
        you the full flexibility to link off-site pages or do other things
        with the generated links (e.g. an URI that turns into
        <code class="code">&lt;a href=&quot;#&quot;&gt;foo&lt;a&gt;</code>).
    </p>

    <div class="section" id="zend.navigation.pages.common"><div class="info"><h1 class="title">Common page features</h1></div>
    

    <p class="para">
        All page classes must extend <span class="classname">Zend_Navigation_Page</span>,
        and will thus share a common set of features and properties. Most notably
        they share the options in the table below and the same initialization
        process.
    </p>

    <p class="para">
        Option keys are mapped to <code class="code">set</code> methods. This means that
        the option <code class="code">order</code> maps to the method  <span class="methodname">setOrder()</span>,
        and <code class="code">reset_params</code> maps to the method
         <span class="methodname">setResetParams()</span>. If there is no setter method for
        the option, it will be set as a custom property of the page.
    </p>

    <p class="para">
        Read more on extending <span class="classname">Zend_Navigation_Page</span> in
        <a href="zend.navigation.pages.html#zend.navigation.pages.custom" class="link">Creating custom page types</a>.
    </p>

    <table id="zend.navigation.pages.common.options" class="doctable table"><div class="info"><caption><b>Common page options</b></caption></div>
        

        
            <thead valign="middle">
                <tr valign="middle">
                    <th>Key</th>
                    <th>Type</th>
                    <th>Default</th>
                    <th>Description</th>
                </tr>

            </thead>


            <tbody valign="middle" class="tbody">
                <tr valign="middle">
                    <td align="left"><code class="code">label</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>
                    <td align="left">A page label, such as &#039;Home&#039; or &#039;Blog&#039;.</td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">id</code></td>
                    <td align="left"><span class="type">String</span> | <code class="code">int</code></td>
                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        An id tag/attribute that may be used when rendering
                        the page, typically in an anchor element.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">class</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        A <acronym class="acronym">CSS</acronym> class that may be used when rendering the page,
                        typically in an anchor element.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">title</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        A short page description, typically for using
                        as the <code class="code">title</code> attribute in an anchor.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">target</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        Specifies a target that may be used for the page,
                        typically in an anchor element.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">rel</code></td>
                    <td align="left"><span class="type">Array</span></td>
                    <td align="left"> <span class="methodname">array()</span></td>

                    <td align="left">
                        Specifies forward relations for the page.
                        Each element in the array is a key-value pair, where the
                        key designates the relation/link type, and the value is
                        a pointer to the linked page. An example of a key-value
                        pair is <code class="code">&#039;alternate&#039; =&gt; &#039;format/plain.html&#039;</code>.
                        To allow full flexbility, there are no restrictions on
                        relation values. The value does not have to be a string.
                        Read more about <code class="code">rel</code> and <code class="code">rev</code> in
                        <a href="zend.view.helpers.html#zend.view.helpers.initial.navigation.links" class="link">the
                        section on the Links helper.</a>.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">rev</code></td>
                    <td align="left"><span class="type">Array</span></td>
                    <td align="left"> <span class="methodname">array()</span></td>

                    <td align="left">
                        Specifies reverse relations for the page. Works exactly
                        like <code class="code">rel</code>.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">order</code></td>

                    <td align="left">
                        <span class="type">String</span> | <code class="code">int</code> | <b><tt>NULL</tt></b>
                    </td>

                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        Works like order for elements in
                        <a href="zend.form.quickstart.html#zend.form.quickstart.render" class="link">
                        <span class="classname">Zend_Form</span></a>. If specified,
                        the page will be iterated in a specific order, meaning
                        you can force a page to be iterated before others by
                        setting the <code class="code">order</code> attribute to a low number,
                        e.g. -100. If a <span class="type">String</span> is given, it must
                        parse to a valid <code class="code">int</code>. If <b><tt>NULL</tt></b>
                        is given, it will be reset, meaning the order in which
                        the page was added to the container will be used.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">resource</code></td>

                    <td align="left">
                        <span class="type">String</span> | <span class="classname">Zend_Acl_Resource_Interface</span>
                        | <b><tt>NULL</tt></b>
                    </td>

                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        <acronym class="acronym">ACL</acronym> resource to associate with the page. Read more in
                        <a href="zend.view.helpers.html#zend.view.helpers.initial.navigation.acl" class="link">the
                        section on <acronym class="acronym">ACL</acronym> integration in view helpers.</a>.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">privilege</code></td>
                    <td align="left"><span class="type">String</span> | <b><tt>NULL</tt></b></td>
                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        <acronym class="acronym">ACL</acronym> privilege to associate with the page. Read more in
                        <a href="zend.view.helpers.html#zend.view.helpers.initial.navigation.acl" class="link">the
                        section on <acronym class="acronym">ACL</acronym> integration in view helpers.</a>.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">active</code></td>
                    <td align="left"><code class="code">bool</code></td>
                    <td align="left"><b><tt>FALSE</tt></b></td>

                    <td align="left">
                        Whether the page should be considered active for the
                        current request. If active is <b><tt>FALSE</tt></b> or not
                        given, <acronym class="acronym">MVC</acronym> pages will check its properties against the
                        request object upon calling <code class="code">$page-&gt;isActive()</code>.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">visible</code></td>
                    <td align="left"><code class="code">bool</code></td>
                    <td align="left"><b><tt>TRUE</tt></b></td>

                    <td align="left">
                        Whether page should be visible for the user, or just
                        be a part of the structure. Invisible pages are skipped
                        by view helpers.
                    </td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">pages</code></td>

                    <td align="left">
                        <span class="type">Array</span> | <span class="classname">Zend_Config</span> |
                        <b><tt>NULL</tt></b>
                    </td>

                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        Child pages of the page. This could be an <span class="type">Array</span>
                        or <span class="classname">Zend_Config</span> object containing either page
                        options that can be passed to the  <span class="methodname">factory()</span>
                        method, or actual <span class="classname">Zend_Navigation_Page</span>
                        instances, or a mixture of both.
                    </td>
                </tr>

            </tbody>
        
    </table>


    <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Custom properties</b><br /></span>
        

        <p class="para">
            All pages support setting and getting of custom properties by
            use of the magic methods  <span class="methodname">__set($name, $value)</span>,
             <span class="methodname">__get($name)</span>,  <span class="methodname">__isset($name)</span> and
             <span class="methodname">__unset($name)</span>. Custom properties may have any value,
            and will be included in the array that is returned from
            <code class="code">$page-&gt;toArray()</code>, which means that pages
            can be serialized/deserialized successfully even if the pages
            contains properties that are not native in the page class.
        </p>

        <p class="para">
            Both native and custom properties can be set using
            <code class="code">$page-&gt;set($name, $value)</code> and retrieved using
            <code class="code">$page-&gt;get($name)</code>, or by using magic methods.
        </p>
    </p></blockquote>

    <div class="example" id="zend.navigation.pages.common.example.customprops"><div class="info"><p><b>Example #1 Custom page properties</b></p></div>
        

        <div class="example-contents"><p>
            This example shows how custom properties can be used.
        </p></div>

        <pre class="programlisting brush: php">
$page = new Zend_Navigation_Page_Mvc();
$page-&gt;foo = &#039;bar&#039;;
$page-&gt;meaning = 42;

echo $page-&gt;foo;

if ($page-&gt;meaning != 42) {
    // action should be taken
}
</pre>

    </div>
</div>
    <div class="section" id="zend.navigation.pages.mvc"><div class="info"><h1 class="title">Zend_Navigation_Page_Mvc</h1></div>
    

    <p class="para">
        <acronym class="acronym">MVC</acronym> pages are defined using <acronym class="acronym">MVC</acronym> parameters known from
        the <span class="classname">Zend_Controller</span> component. An <acronym class="acronym">MVC</acronym> page will
        use <span class="classname">Zend_Controller_Action_Helper_Url</span> internally
        in the  <span class="methodname">getHref()</span> method to generate hrefs, and
        the  <span class="methodname">isActive()</span> method will intersect the
        <span class="classname">Zend_Controller_Request_Abstract</span> params
        with the page&#039;s params to determine if the page is active.
    </p>

    <table id="zend.navigation.pages.mvc.options" class="doctable table"><div class="info"><caption><b>MVC page options</b></caption></div>
        

        
            <thead valign="middle">
                <tr valign="middle">
                    <th>Key</th>
                    <th>Type</th>
                    <th>Default</th>
                    <th>Description</th>
                </tr>

            </thead>


            <tbody valign="middle" class="tbody">
                <tr valign="middle">
                    <td align="left"><code class="code">action</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>
                    <td align="left">Action name to use when generating href to the page.</td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">controller</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>
                    <td align="left">Controller name to use when generating href to the page.</td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">module</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>
                    <td align="left">Module name to use when generating href to the page.</td>
                </tr>


                <tr valign="middle">
                    <td align="left"><code class="code">params</code></td>
                    <td align="left"><span class="type">Array</span></td>
                    <td align="left"> <span class="methodname">array()</span></td>
                    <td align="left">User params to use when generating href to the page.</td>
                </tr>

                <tr valign="middle">
                    <td align="left"><code class="code">route</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>
                    <td align="left">Route name to use when generating href to the page.</td>
                </tr>

                <tr valign="middle">
                    <td align="left"><code class="code">reset_params</code></td>
                    <td align="left"><code class="code">bool</code></td>
                    <td align="left"><b><tt>TRUE</tt></b></td>

                    <td align="left">
                        Whether user params should be reset when generating href to the page.
                    </td>
                </tr>

            </tbody>
        
    </table>


    <blockquote class="note"><p><b class="note">Note</b>: 
        <p class="para">
            The three examples below assume a default <acronym class="acronym">MVC</acronym> setup with
            the <code class="code">default</code> route in place.
        </p>

        <p class="para">
            The <acronym class="acronym">URI</acronym> returned is relative to the <code class="code">baseUrl</code> in
            <span class="classname">Zend_Controller_Front</span>. In the examples, the baseUrl
            is &#039;/&#039; for simplicity.
        </p>
    </p></blockquote>

    <div class="example" id="zend.navigation.pages.mvc.example.getHref"><div class="info"><p><b>Example #2 getHref() generates the page URI</b></p></div>
        

        <div class="example-contents"><p>
            This example shows that <acronym class="acronym">MVC</acronym> pages use
            <span class="classname">Zend_Controller_Action_Helper_Url</span> internally
            to generate <acronym class="acronym">URI</acronym>s when calling <code class="code">$page-&gt;getHref()</code>.
        </p></div>

        <pre class="programlisting brush: php">
// getHref() returns /
$page = new Zend_Navigation_Page_Mvc(array(
    &#039;action&#039;     =&gt; &#039;index&#039;,
    &#039;controller&#039; =&gt; &#039;index&#039;
));

// getHref() returns /blog/post/view
$page = new Zend_Navigation_Page_Mvc(array(
    &#039;action&#039;     =&gt; &#039;view&#039;,
    &#039;controller&#039; =&gt; &#039;post&#039;,
    &#039;module&#039;     =&gt; &#039;blog&#039;
));

// getHref() returns /blog/post/view/id/1337
$page = new Zend_Navigation_Page_Mvc(array(
    &#039;action&#039;     =&gt; &#039;view&#039;,
    &#039;controller&#039; =&gt; &#039;post&#039;,
    &#039;module&#039;     =&gt; &#039;blog&#039;,
    &#039;params&#039;     =&gt; array(&#039;id&#039; =&gt; 1337)
));
</pre>

    </div>

    <div class="example" id="zend.navigation.pages.mvc.example.isActive"><div class="info"><p><b>Example #3 isActive() determines if page is active</b></p></div>
        

        <div class="example-contents"><p>
            This example shows that <acronym class="acronym">MVC</acronym> pages determine whether they are active
            by using the params found in the request object.
        </p></div>

        <pre class="programlisting brush: php">
/*
 * Dispatched request:
 * - module:     default
 * - controller: index
 * - action:     index
 */
$page1 = new Zend_Navigation_Page_Mvc(array(
    &#039;action&#039;     =&gt; &#039;index&#039;,
    &#039;controller&#039; =&gt; &#039;index&#039;
));

$page2 = new Zend_Navigation_Page_Mvc(array(
    &#039;action&#039;     =&gt; &#039;bar&#039;,
    &#039;controller&#039; =&gt; &#039;index&#039;
));

$page1-&gt;isActive(); // returns true
$page2-&gt;isActive(); // returns false

/*
 * Dispatched request:
 * - module:     blog
 * - controller: post
 * - action:     view
 * - id:         1337
 */
$page = new Zend_Navigation_Page_Mvc(array(
    &#039;action&#039;     =&gt; &#039;view&#039;,
    &#039;controller&#039; =&gt; &#039;post&#039;,
    &#039;module&#039;     =&gt; &#039;blog&#039;
));

// returns true, because request has the same module, controller and action
$page-&gt;isActive();

/*
 * Dispatched request:
 * - module:     blog
 * - controller: post
 * - action:     view
 */
$page = new Zend_Navigation_Page_Mvc(array(
    &#039;action&#039;     =&gt; &#039;view&#039;,
    &#039;controller&#039; =&gt; &#039;post&#039;,
    &#039;module&#039;     =&gt; &#039;blog&#039;,
    &#039;params&#039;     =&gt; array(&#039;id&#039; =&gt; null)
));

// returns false, because page requires the id param to be set in the request
$page-&gt;isActive(); // returns false
</pre>

    </div>

    <div class="example" id="zend.navigation.pages.mvc.example.routes"><div class="info"><p><b>Example #4 Using routes</b></p></div>
        

        <div class="example-contents"><p>
            Routes can be used with <acronym class="acronym">MVC</acronym> pages. If a page has a route, this
            route will be used in  <span class="methodname">getHref()</span> to generate the
            <acronym class="acronym">URL</acronym> for the page.
        </p></div>

        <div class="example-contents"><p>
            <blockquote class="note"><p><b class="note">Note</b>: 
                <p class="para">
                    Note that when using the <code class="code">route</code> property in a
                    page, you should also specify the default params that the
                    route defines (module, controller, action, etc.), otherwise
                    the  <span class="methodname">isActive()</span> method will not be able to
                    determine if the page is active. The reason for this is that
                    there is currently no way to get the default params from a
                    <span class="classname">Zend_Controller_Router_Route_Interface</span> object,
                    nor to retrieve the current route from a
                    <span class="classname">Zend_Controller_Router_Interface</span> object.
                </p>
            </p></blockquote>
        </p></div>

        <pre class="programlisting brush: php">
// the following route is added to the ZF router
Zend_Controller_Front::getInstance()-&gt;getRouter()-&gt;addRoute(
    &#039;article_view&#039;, // route name
    new Zend_Controller_Router_Route(
        &#039;a/:id&#039;,
        array(
            &#039;module&#039;     =&gt; &#039;news&#039;,
            &#039;controller&#039; =&gt; &#039;article&#039;,
            &#039;action&#039;     =&gt; &#039;view&#039;,
            &#039;id&#039;         =&gt; null
        )
    )
);

// a page is created with a &#039;route&#039; option
$page = new Zend_Navigation_Page_Mvc(array(
    &#039;label&#039;      =&gt; &#039;A news article&#039;,
    &#039;route&#039;      =&gt; &#039;article_view&#039;,
    &#039;module&#039;     =&gt; &#039;news&#039;,    // required for isActive(), see note above
    &#039;controller&#039; =&gt; &#039;article&#039;, // required for isActive(), see note above
    &#039;action&#039;     =&gt; &#039;view&#039;,    // required for isActive(), see note above
    &#039;params&#039;     =&gt; array(&#039;id&#039; =&gt; 42)
));

// returns: /a/42
$page-&gt;getHref();
</pre>

    </div>
</div>
    <div class="section" id="zend.navigation.pages.uri"><div class="info"><h1 class="title">Zend_Navigation_Page_Uri</h1></div>
    

    <p class="para">
        Pages of type <span class="classname">Zend_Navigation_Page_Uri</span> can be
        used to link to pages on other domains or sites, or to implement
        custom logic for the page. <acronym class="acronym">URI</acronym> pages are simple; in addition
        to the common page options, a <acronym class="acronym">URI</acronym> page takes only one option —
        <code class="code">uri</code>. The <code class="code">uri</code> will be returned when
        calling <code class="code">$page-&gt;getHref()</code>, and may be a
        <span class="type">String</span> or <b><tt>NULL</tt></b>.
    </p>

    <blockquote class="note"><p><b class="note">Note</b>: 
        <p class="para">
            <span class="classname">Zend_Navigation_Page_Uri</span> will not try to determine
            whether it should be active when calling <code class="code">$page-&gt;isActive()</code>.
            It merely returns what currently is set, so to make a <acronym class="acronym">URI</acronym> page active
            you have to manually call <code class="code">$page-&gt;setActive()</code> or
            specifying <code class="code">active</code> as a page option when constructing.
        </p>
    </p></blockquote>

    <table id="zend.navigation.pages.uri.options" class="doctable table"><div class="info"><caption><b>URI page options</b></caption></div>
        

        
            <thead valign="middle">
                <tr valign="middle">
                    <th>Key</th>
                    <th>Type</th>
                    <th>Default</th>
                    <th>Description</th>
                </tr>

            </thead>


            <tbody valign="middle" class="tbody">
                <tr valign="middle">
                    <td align="left"><code class="code">uri</code></td>
                    <td align="left"><span class="type">String</span></td>
                    <td align="left"><b><tt>NULL</tt></b></td>

                    <td align="left">
                        <acronym class="acronym">URI</acronym> to page. This can be any string or
                        <b><tt>NULL</tt></b>.
                    </td>
                </tr>

            </tbody>
        
    </table>

</div>
    <div class="section" id="zend.navigation.pages.custom"><div class="info"><h1 class="title">Creating custom page types</h1></div>
    

    <p class="para">
        When extending <span class="classname">Zend_Navigation_Page</span>, there is
        usually no need to override the constructor or the methods
         <span class="methodname">setOptions()</span> or  <span class="methodname">setConfig()</span>. The page
        constructor takes a single parameter, an <span class="type">Array</span> or a
        <span class="classname">Zend_Config</span> object, which is passed to
         <span class="methodname">setOptions()</span> or  <span class="methodname">setConfig()</span> respectively.
        Those methods will in turn call  <span class="methodname">set()</span> method, which
        will map options to native or custom properties. If the option
        <span class="property">internal_id</span> is given, the method will first look for a
        method named  <span class="methodname">setInternalId()</span>, and pass the option to this
        method if it exists. If the method does not exist, the option will be
        set as a custom property of the page, and be accessible via
        <strong class="command">$internalId = $page-&gt;internal_id;</strong> or
        <strong class="command">$internalId = $page-&gt;get(&#039;internal_id&#039;);</strong>.
    </p>

    <div class="example" id="zend.navigation.custom.example.simple"><div class="info"><p><b>Example #5 The most simple custom page</b></p></div>
        

        <div class="example-contents"><p>
            The only thing a custom page class needs to implement is the
             <span class="methodname">getHref()</span> method.
        </p></div>

        <pre class="programlisting brush: php">
class My_Simple_Page extends Zend_Navigation_Page
{
    public function getHref()
    {
        return &#039;something-completely-different&#039;;
    }
}
</pre>

    </div>

    <div class="example" id="zend.navigation.custom.example.properties"><div class="info"><p><b>Example #6 A custom page with properties</b></p></div>
        

        <div class="example-contents"><p>
            When adding properties to an extended page, there is no need
            to override/modify  <span class="methodname">setOptions()</span> or
             <span class="methodname">setConfig()</span>.
        </p></div>

        <pre class="programlisting brush: php">
class My_Navigation_Page extends Zend_Navigation_Page
{
    private $_foo;
    private $_fooBar;

    public function setFoo($foo)
    {
        $this-&gt;_foo = $foo;
    }

    public function getFoo()
    {
        return $this-&gt;_foo;
    }

    public function setFooBar($fooBar)
    {
        $this-&gt;_fooBar = $fooBar;
    }

    public function getFooBar()
    {
        return $this-&gt;_fooBar;
    }

    public function getHref()
    {
        return $this-&gt;foo . &#039;/&#039; . $this-&gt;fooBar;
    }
}

// can now construct using
$page = new My_Navigation_Page(array(
    &#039;label&#039;   =&gt; &#039;Property names are mapped to setters&#039;,
    &#039;foo&#039;     =&gt; &#039;bar&#039;,
    &#039;foo_bar&#039; =&gt; &#039;baz&#039;
));

// ...or
$page = Zend_Navigation_Page::factory(array(
    &#039;type&#039;    =&gt; &#039;My_Navigation_Page&#039;,
    &#039;label&#039;   =&gt; &#039;Property names are mapped to setters&#039;,
    &#039;foo&#039;     =&gt; &#039;bar&#039;,
    &#039;foo_bar&#039; =&gt; &#039;baz&#039;
));
</pre>

    </div>
</div>
    <div class="section" id="zend.navigation.pages.factory"><div class="info"><h1 class="title">Creating pages using the page factory</h1></div>
    

    <p class="para">
        All pages (also custom classes), can be created using the page
        factory,  <span class="methodname">Zend_Navigation_Page::factory()</span>. The factory
        can take an array with options, or a
        <span class="classname">Zend_Config</span> object. Each key in the
        array/config corresponds to a page option, as seen in the
        section on <a href="zend.navigation.pages.html" class="link">Pages</a>.
        If the option <code class="code">uri</code> is given and no <acronym class="acronym">MVC</acronym> options are
        given (<code class="code">action, controller, module, route</code>), an <acronym class="acronym">URI</acronym>
        page will be created. If any of the <acronym class="acronym">MVC</acronym> options are given, an
        <acronym class="acronym">MVC</acronym> page will be created.
    </p>

    <p class="para">
        If <code class="code">type</code> is given, the factory will assume the value to
        be the name of the class that should be created. If the value is
        <code class="code">mvc</code> or <code class="code">uri</code> and <acronym class="acronym">MVC</acronym>/URI page will be created.
    </p>

    <div class="example" id="zend.navigation.pages.factory.example.mvc"><div class="info"><p><b>Example #7 Creating an MVC page using the page factory</b></p></div>
        

        <pre class="programlisting brush: php">
$page = Zend_Navigation_Page::factory(array(
    &#039;label&#039;  =&gt; &#039;My MVC page&#039;,
    &#039;action&#039; =&gt; &#039;index&#039;
));

$page = Zend_Navigation_Page::factory(array(
    &#039;label&#039;      =&gt; &#039;Search blog&#039;,
    &#039;action&#039;     =&gt; &#039;index&#039;,
    &#039;controller&#039; =&gt; &#039;search&#039;,
    &#039;module&#039;     =&gt; &#039;blog&#039;
));

$page = Zend_Navigation_Page::factory(array(
    &#039;label&#039;      =&gt; &#039;Home&#039;,
    &#039;action&#039;     =&gt; &#039;index&#039;,
    &#039;controller&#039; =&gt; &#039;index&#039;,
    &#039;module&#039;     =&gt; &#039;index&#039;,
    &#039;route&#039;      =&gt; &#039;home&#039;
));

$page = Zend_Navigation_Page::factory(array(
    &#039;type&#039;   =&gt; &#039;mvc&#039;,
    &#039;label&#039;  =&gt; &#039;My MVC page&#039;
));
</pre>

    </div>

    <div class="example" id="zend.navigation.pages.factory.example.uri"><div class="info"><p><b>Example #8 Creating a URI page using the page factory</b></p></div>
        

        <pre class="programlisting brush: php">
$page = Zend_Navigation_Page::factory(array(
    &#039;label&#039; =&gt; &#039;My URI page&#039;,
    &#039;uri&#039;   =&gt; &#039;http://www.example.com/&#039;
));

$page = Zend_Navigation_Page::factory(array(
    &#039;label&#039;  =&gt; &#039;Search&#039;,
    &#039;uri&#039;    =&gt; &#039;http://www.example.com/search&#039;,
    &#039;active&#039; =&gt; true
));

$page = Zend_Navigation_Page::factory(array(
    &#039;label&#039; =&gt; &#039;My URI page&#039;,
    &#039;uri&#039;   =&gt; &#039;#&#039;
));

$page = Zend_Navigation_Page::factory(array(
    &#039;type&#039;   =&gt; &#039;uri&#039;,
    &#039;label&#039;  =&gt; &#039;My URI page&#039;
));
</pre>

    </div>

    <div class="example" id="zend.navigation.pages.factory.example.custom"><div class="info"><p><b>Example #9 Creating a custom page type using the page factory</b></p></div>
        

        <div class="example-contents"><p>
            To create a custom page type using the factory, use the option
            <code class="code">type</code> to specify a class name to instantiate.
        </p></div>

        <pre class="programlisting brush: php">
class My_Navigation_Page extends Zend_Navigation_Page
{
    protected $_fooBar = &#039;ok&#039;;

    public function setFooBar($fooBar)
    {
        $this-&gt;_fooBar = $fooBar;
    }
}

$page = Zend_Navigation_Page::factory(array(
    &#039;type&#039;    =&gt; &#039;My_Navigation_Page&#039;,
    &#039;label&#039;   =&gt; &#039;My custom page&#039;,
    &#039;foo_bar&#039; =&gt; &#039;foo bar&#039;
));
</pre>

    </div>
</div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.navigation.introduction.html">Introduction</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.navigation.html">Zend_Navigation</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.navigation.containers.html">Containers</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.navigation.html">Zend_Navigation</a></li>
  <li><a href="zend.navigation.introduction.html">Introduction</a></li>
  <li class="active"><a href="zend.navigation.pages.html">Pages</a></li>
  <li><a href="zend.navigation.containers.html">Containers</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>